<template>
  <div>
    <van-dropdown-menu>
      <van-dropdown-item v-model="area" :options="areas" @change="onChange" />
    </van-dropdown-menu>
  </div>
</template>

<script>
import { get } from "@/api/common";
export default {
  props:['objectName','fieldName'],
  data() {
    return {
      areas: [],
      area: '',
      show: false,
    };
  },
  mounted() {
    this.getAreas();
  },
  methods: {
    onChange(picker, value, index) {
        this.show = false;
        this.area = value.text;
        this.$emit('selectedType',value.id);
    },
    // 调用api获得酒店类型列表
    getAreas() {
    let params={
        'Dicts[]': {
            'Dicts': {
                '@column': 'name:text,value:id',
                'object': this.objectName,
                'field': this.fieldName
            }
        }
    };
    let that = this;
    get(params)
        .then(function (res) {
        var data = res.data["Dicts[]"]
        for(var d in data){
            that.areas.push({text:data[d].text,id:data[d].id,selected:false});
        }
        })
        .catch(function (error){
            console.log(error);
        });
    },
  },
};
</script>
